package com.example.demo.controller;

import com.example.demo.vo.RedisModel;
import com.example.demo.service.RedisService;
import com.example.demo.utils.JsonResult;
import com.example.demo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/redis")
@RestController
public class RedisController {
    @Autowired
    private RedisService redisService;

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public JsonResult addRedis(@RequestBody RedisModel from){
        redisService.addRedis(from.getKey(),from.getValue());
        return ResultUtil.success("添加成功");
    }

    @RequestMapping(value = "/del",method = RequestMethod.DELETE)
    public JsonResult delRedis(String key){
        redisService.delRedis(key);
        return ResultUtil.success("删除成功");
    }

    @RequestMapping(value = "/redisPage",method = RequestMethod.GET)
    public JsonResult getRedisPage(){
        return redisService.getAllRedis();
    }
}
